package cn.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.*;

@Repository //自动识别为一个bean
public class StuDao {
  @Autowired //自动绑定，默认按照类型绑定
  DataSource dataSource;
  String sql = "select * from stu";

  public void query() throws Exception{
    try (Connection con = dataSource.getConnection();
         PreparedStatement pstmt = con.prepareStatement(sql);
         ResultSet rs = pstmt.executeQuery()) {
      while (rs.next()) {
        System.out.println(rs.getString("name"));
      }
    }
  }
}
